public class LogIn1 {

    private String userName = "admin";
    private String password = "123456";

    public  void loginInfo1(String userName, String password) {
        try {
            if (!this.userName.equals(userName)) {
                throw new UserNameErrorException1("用户名错误！");
                //比下面的sout+return有用
                //原因：一旦输出控制台(后端)那一部分输出很多东西，如果用sout来看，很难找到错误。
                //System.out.println("用户名错误！");
                //return;
            }
            if (!this.password.equals(password)) {
                throw new PassWordException1("密码错误！");
            /*System.out.println("密码错误！");
            return;*/
            }
            System.out.println("登陆成功");
        }catch (UserNameErrorException1 e) {
            //请重新输入密码  进行判断
            e.printStackTrace();
        }catch (PassWordException1 e) {
            e.printStackTrace();
        }
    }
    public  void loginInfo(String userName, String password)
            throws UserNameErrorException1,PassWordException1{
        if (!this.userName.equals(userName)) {
            throw new UserNameErrorException1("用户名错误！");
            //System.out.println("用户名错误！");
            //return;
        }
        if (!this.password.equals(password)) {
            throw new PassWordException1("密码错误！");
        /*System.out.println("密码错误！");
        return;*/
        }
        System.out.println("登陆成功");
    }
    public static void main(String[] args)  {
        try {
            LogIn1 logIn = new LogIn1();
            logIn.loginInfo("admin2", "123456");
        }catch (UserNameErrorException1 e) {
            //请重新输入密码  进行判断
            e.printStackTrace();
        }catch (PassWordException1 e) {
            e.printStackTrace();
        }
    }
}